﻿#region File Header
/***********************************************************************
 * Copyright © 2013 Beals Software
 * All Rights Reserved
************************************************************************
Author: Donald Beals
Date: February 4th, 2013
Description: TODO: Write a description of this file here.
****************************** Change Log ******************************
02.04.13 - Created initial file. (dbeals)
***********************************************************************/
#endregion

#region Using Statements
using System;
using GameJolt.Async;
using GameJolt.Requests;
using Newtonsoft.Json;
#endregion

namespace GameJolt
{
	/// <summary>
	/// 
	/// </summary>
	[JsonObject]
	public sealed class HighScoreTable
	{
		#region Properties
		[JsonProperty("id")]
		public string ID
		{
			get;
			set;
		}

		[JsonProperty("name")]
		public string Name
		{
			get;
			set;
		}

		[JsonProperty("description")]
		public string Description
		{
			get;
			set;
		}

		[JsonProperty("primary")]
		public string Primary
		{
			get;
			set;
		}
		#endregion

		#region Constructors
		public HighScoreTable()
		{
		}
		#endregion

		#region Methods
		public static IAsyncResult BeginGetTables(string gameID, string privateKey, AsyncCallback callback = null, object asyncState = null)
		{
			var request = ScoreRequestFactory.CreateGetTablesRequest(gameID, privateKey);
			return request.Begin(callback, asyncState);
		}

		public static HighScoreTable[] EndGetTables(IAsyncResult result)
		{
			var joltResult = (AsyncResult<HighScoreTable[]>)result;
			var request = (JsonRequest<HighScoreTable[], ScoreRequestFactory.HighScoreTableRequestResult>)joltResult.CoreData;
			return request.End(result);
		}

		public static HighScoreTable[] GetTables(string gameID, string privateKey)
		{
			var request = ScoreRequestFactory.CreateGetTablesRequest(gameID, privateKey);
			return request.Process(null);
		}

		public static IAsyncResult GetTables(string gameID, string privateKey, Action<HighScoreTable[]> callback)
		{
			return BeginGetTables(gameID, privateKey, (result) => callback(EndGetTables(result)));
		}
		#endregion
	}
}
